<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ws_test</title>
</head>
<body>
<script type="text/javascript">
    var ws=null;
    function testWS()
    {
        if("WebSocket" in window)
        {
            console.log("您的浏览器支持 WebSocket");
            return true;
        }
        else
        {
            console.log("Sorry！Your browser doesn't support WebSocket!")
            return false;
        }
    }
function danmu_ws()
{
    var is_support=testWS();
    var rece_msg_json={};
    if (is_support==true)
    {
         ws=new WebSocket("ws://" + window.location.host + "/danmu_resolution");
        ws.onopen=function (ev){
          console.log("client open ws")
        }
        ws.onmessage=function (ev) {
            var receive_msg=ev.data
console.log("数据接收："+receive_msg+typeof(receive_msg));
            if(receive_msg.search("{")>=0)
            {
           //console.log("数据接收："+receive_msg+typeof(receive_msg));
                    rece_msg_json=JSON.parse(receive_msg)
                    console.log("json:"+rece_msg_json)

            }
            else if(receive_msg=="endoff")
            {
                ws_transfer()
            }
            else if(receive_msg.search("url set ok")>=0)
            {
                 ws_transfer()
            }
        }
        ws.onclose=function (ev) {
            console.log("连接已经关闭！");
        }

    }
    else{
        return false;
    }
}
window.onload=function (ev) {
        danmu_ws();
}
function ws_transfer()
{
    ws.send("danmu_ws transferring");
    console.log("正在发送数据:tranferring");
}
function ws_danmu_fetch()
{
    var url_text=document.getElementById("url_input").value
    console.log(url_text)
    ws.send(url_text)

}
</script>
<input type="text" size="30" id="url_input">
<a href=javascript:ws_danmu_fetch()>获取弹幕</a>
</body>
</html>